<?php

class Db {
    static private $_dit = null;
    private $_dbVerbinding = null;
    
    private function __construct()  {
        $configBestand = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'Db.ini.php';
        if (!file_exists($configBestand) || !is_readable($configBestand)) {
            die('FATAAL... databaseconfiguratie fout');
        }
        
        require_once($configBestand);
        $verbinding = 'mysql:host='.$dbConfig['host'].';';
        if (!empty($dbConfig['poort'])) {
            $verbinding .= 'port='.$dbConfig['poort'].';';
        }
        $verbinding .= 'dbname='.$dbConfig['database'];
        $gebruiker = $dbConfig['gebruiker'];
        $wachtwoord = $dbConfig['wachtwoord'];
        
        try {
            $this->_dbVerbinding = new PDO($verbinding,$gebruiker,$wachtwoord);
        } 
        catch (PDOException $ex) {
            die('FATAAL... '.$ex->getMessage());
        }
    }
    
    static public function GET() {
        if (!(self::$_dit instanceof self)) {
            self::$_dit = new self();
        }
        
        return self:: $_dit->_dbVerbinding;
    }
}
